package com.dongjiantong.app.controller.biz;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongjiantong.biz.model.DjtButcherReportsForms;
import com.dongjiantong.biz.service.DjtButcherReportsFormsService;
import com.dongjiantong.common.exceptions.HttpCode;
import com.dongjiantong.common.exceptions.OPServerException;
import com.dongjiantong.common.model.Response;
import com.dongjiantong.openplatform.annotations.OpenBean;
import com.dongjiantong.openplatform.annotations.OpenMethod;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMethod;


import java.util.Date;

/**
 * Created by ldf on 2017/11/20.
 */
@Slf4j
@OpenBean
public class DjtButcherReportsFormsController {

    @Reference(version = "1.0.0")
    private DjtButcherReportsFormsService djtButcherReportsFormsService;


    /**
     * 根据官方兽医查询所有 屠宰检疫报表
     *
     * @param vetUserId 官方兽医ID
     * @param pageNum   页码
     * @param pageSize  一页几条
     * @return
     */
    @OpenMethod(
            key = "app.DjtButcherReportsForms.selectByVetUserId",
            paramNames = {"vetUserId", "pageNum", "pageSize"},
            httpMethods = RequestMethod.POST)
    public Response<PageInfo<DjtButcherReportsForms>> selectByVetUserId(Long vetUserId, int pageNum, int pageSize) {

        if (vetUserId == null) {
            throw new OPServerException(HttpCode.BAD_REQUEST, "官方兽医ID为空");
        }

        DjtButcherReportsForms djtButcherReportsForms = new DjtButcherReportsForms();
        djtButcherReportsForms.setVet_user_id(vetUserId);
        try {
            PageInfo<DjtButcherReportsForms> djtButcherReportsFormsPageInfo = djtButcherReportsFormsService.selectPage(pageNum, pageSize, djtButcherReportsForms);
            return Response.ok(djtButcherReportsFormsPageInfo);
        } catch (Exception e) {
            log.error(e.getMessage());
            throw new OPServerException(HttpCode.INTERNAL_SERVER_ERROR, "查询出错请稍后再试");
        }


    }

    /**
     * 根据官方兽医查询 和时间段查询 屠宰检疫报表
     *
     * @param startTime
     * @param endTime
     * @param pageNum
     * @param pageSize
     * @param vetUserId
     * @return
     */
    @OpenMethod(
            key = "app.DjtButcherReportsForms.selectByVetUserIdAndReportTime",
            paramNames = {"startTime", "endTime", "pageNum", "pageSize", "vetUserId"},
            httpMethods = RequestMethod.POST)
    public Response<PageInfo<DjtButcherReportsForms>> selectByVetUserIdAndReportTime(Date startTime, Date endTime, int pageNum, int pageSize, Long vetUserId) {

        if (vetUserId == null) {
            throw new OPServerException(HttpCode.BAD_REQUEST, "官方兽医ID为空");
        }

        try {
            PageInfo<DjtButcherReportsForms> pageInfo = djtButcherReportsFormsService.selectByVetUserIdAndReportTime(startTime, endTime, pageNum, pageSize, vetUserId);
            return Response.ok(pageInfo);
        } catch (Exception e) {
            log.error(e.getMessage());
            throw new OPServerException(HttpCode.INTERNAL_SERVER_ERROR, "查询异常请稍后再试");
        }


    }


}
